// pages/bm/detail/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        readOnly:true,
        posterFlag:false,
        username:'',
        mobile:'',
        imgH:'',
        info:null,
        id:0,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if(options.id) {
          this.data.id = options.id;
          this.getRecord();
        }
        if(options.status) {
            this.setData({
                status:options.status
            })
        }

    },

    getRecord(){
      const that = this;
      wx.request({
        url: app.globalData.apiUrl + 'api/activity/detail',
        method: 'POST',
        data: {
          'openid':wx.getStorageSync('openid'),
          'id':that.data.id,
        },
        header: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          let response = res.data.data;
          that.setData({
              info:response
          })
        },
        fail: function () {
          
        },
        complete: function () {
        }
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    joinIn(){
        this.setData({
            posterFlag:true,
            username:'',
            mobile:''
          })
    },
    makePoster(e){
   
      if(!this.data.posterFlag) {
        this.setData({
          posterFlag:true,
          username:'',
          mobile:''
        })
        return ;
      }
      let type = e.currentTarget.dataset.type;
      console.log(e);
      if(type=='confirm')     {
        if(!this.data.username) {
          wx.showToast({
            'icon':'error',
            title: '请录入姓名',
          })
          return ;
        }
        if(!this.data.mobile) {
            wx.showToast({
              'icon':'error',
              title: '请录入手机号',
            })
            return ;
          }
        
      }
      this.DoJoin();
      this.setData({
        posterFlag:false
      })
    },
    DoJoin(){
      const that = this;
      wx.request({
        url: app.globalData.apiUrl + 'api/activity/join',
        method: 'POST',
        data: {
          'openid':wx.getStorageSync('openid'),
          'id':that.data.id,
          'name':that.data.username,
          'mobile':that.data.mobile
        },
        header: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
            if(res.data.code == 0) {
              // wx.showToast({icon:'error', title:res.data.msg});
              wx.showModal({
                title: '报名失败',
                content: res.data.msg
              })
            }
            else{
              wx.showToast({
                icon:'none',
                title: res.data.msg,
              })
            }
            console.log(res);
        },
        fail: function () {
          
        },
        complete: function () {
        }
      })
    },
  setUser(e){
    this.setData({
      username:e.detail.value
    })
  },
  
  setMobile(e){
    this.setData({
      mobile:e.detail.value
    })
  },
  imgload(e){
        let width = e.detail.width;
        let height = e.detail.height;

        let w = 730;
        let h = w*height/width;
        console.log('h', e)
        console.log('h', h)
        this.setData({
            imgH:h+'rpx'
        })
  }
})